package com.ikangtai.shecare.stickycalendar.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ikangtai.shecare.R;
import com.ikangtai.shecare.stickycalendar.bean.OvulationMoreBean;

import java.util.List;

/**
 * Created by lijinyuan on 16/8/19.
 */
public class OvulationTestMoreAdapter extends BaseAdapter {
    private List<OvulationMoreBean> mlist;
    private Context mContext;
    private ViewHolder viewHolder;
    private int mLastPosition;
    private View mLastView;

    public OvulationTestMoreAdapter(Context context, List<OvulationMoreBean> list) {
        this.mLastPosition = -1;
        this.mContext = context;
        this.mlist = list;
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder = new ViewHolder();
        LayoutInflater inflater = LayoutInflater.from(mContext);
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.ca_re_more_ovulation, null);
            viewHolder.ca_re_ovulation_title = (TextView) convertView.findViewById(R.id.ca_re_ovulation_title);
            viewHolder.ca_re_ovulation_img = (ImageView) convertView.findViewById(R.id.ca_re_ovulation_img);
            viewHolder.ca_re_ovulation_choose = (ImageView) convertView.findViewById(R.id.ca_re_ovulation_choose);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.ca_re_ovulation_img.setImageResource(mlist.get(position).getImg());
        viewHolder.ca_re_ovulation_title.setText(mlist.get(position).getTitle());
        if (mlist.get(position).getChoose() > 1) {
            viewHolder.ca_re_ovulation_choose.setImageResource((mlist.get(position).getChoose() % 2) == 0 ? R.drawable.red_ovulation_state_no : R.drawable.red_ovulation_state);
        } else {
            viewHolder.ca_re_ovulation_choose.setImageResource((mlist.get(position).getChoose() % 2) == 0 ? R.drawable.red_ovulation_state_no : R.drawable.green_ovulation_state);
        }
        return convertView;

    }


    public class ViewHolder {
        private ImageView ca_re_ovulation_img, ca_re_ovulation_choose;
        private TextView ca_re_ovulation_title;
    }


}
